package com.example.HelloSpace.database.daos;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import com.example.HelloSpace.database.entities.SpaceMissionEntity;

import java.util.List;

@Dao
public interface SpaceMissionDao {
    // 主键存在时，冲突策略为替换
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(SpaceMissionEntity... mission);

    @Query("DELETE FROM space_missions WHERE id = :missionId")
    void deleteSpaceMissionById(long missionId);

    @Query("SELECT * FROM space_missions ORDER BY launchTimeUtc ASC")
    LiveData<List<SpaceMissionEntity>> getAllMissions();

    @Query("SELECT * FROM space_missions ORDER BY launchTimeUtc ASC")
    List<SpaceMissionEntity> getAllMissionsList();

    // 新增：删除所有数据
    @Query("DELETE FROM space_missions")
    void deleteAll();

    @Query("SELECT EXISTS(SELECT 1 FROM space_missions WHERE id = :id)")
    Boolean isMissionExists(long id);

    @Query("SELECT COUNT(*) FROM space_missions")
    LiveData<Integer> getTotalMissionCount();
}
